@extends('admin.layouts.base')
@section('title','产品列表')
@section('pageHeader','产品列表')

@section('content')
    <div class="row">
        <div class="col-lg-12">
            {{--提示信息弹出框--}}
            @include('admin.partials.errors')
            @include('admin.partials.success')
            {{--提示信息弹出框--}}

            <div class="box box-success">
                {{--内容主体 开始--}}
                <div class="box-header">
                    <h1 class="box-title">产品列表</h1>
                </div>

                <div class="box-body">
                    <table id="data-table" class="table table-striped">
                        <thead>
                        <tr>
                            <td>#</td>
                            <td>产品LOGO</td>
                            <td>产品名</td>
                            <td>在线状态</td>
                            <td>操&nbsp;&nbsp;作</td>
                        </tr>
                        </thead>
                        <tbody>
                        @foreach($data as $index => $item)
                            <tr>
                                <td>{{ $index + 1 }}</td>
                                <td>
                                    @if($item)
                                    <img src="{{$item->product ->product_logo}}" width="100px" height="auto">
                                        @endif
                                </td>
                                <td>
                                    @if($item)
                                        {{$item->product ->name}}
                                    @endif
                                </td>
                                <td>{{ \App\Models\Orm\Product::getStatusText($item->status) }}</td>
                                <td>
                                    @if(Gate::forUser(auth('admin')->user())->check('admin.loading.delete'))
                                        <a href="{{ url('/admin/loading/delete/' . $item->id) }}">
                                            删除
                                        </a>
                                    @endif
                                        <a href="#" class="shengxu" onclick="shengxu('{{ $item['id']}}' )"><i
                                                    class="fa fa-arrow-up"></i>升序</a>
                                        &nbsp;&nbsp;
                                        <a href="#" class="jiangxu" onclick="jiangxu('{{ $item['id']}}' )"><i
                                                    class="fa fa-arrow-down"></i>降序</a>
                                </td>
                            </tr>
                        @endforeach
                        </tbody>
                    </table>
                </div>

                <div class="box-footer">
                    <div class="pull-right">
                        @if(Gate::forUser(auth('admin')->user())->check('admin.loading.create'))
                            <a href="{{ url('/admin/loading/create') }}">
                                <button class="btn btn-primary btn-sm">添加产品</button>
                            </a>
                        @endif
                    </div>
                </div>
                {{--内容主体 结束--}}

            </div>
        </div>
    </div>
@endsection

@section('js')
    <script>



        function shengxu(id) {
            $.ajax({
                type: 'POST',
                url: "{{ url('/admin/loading/ajaxShengXu')}}",
                data: {id: id},
                success: function (data) {
                    if (data == 1) {
                        window.history.go(0);
                    }
                },
                error: function () {
                    alert('异常');
                }
            });
        }

        function jiangxu(id) {
            $.ajax({
                type: 'POST',
                url: "{{ url('/admin/loading/ajaxJiangXu')}}",
                data: {id: id},
                success: function (data) {
                    if (data == 1) {
                        window.history.go(0);
                    }
                },
                error: function () {
                    alert('异常');
                }
            });
        }


        window.onload = function () {
            $.ajaxSetup({
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                }
            });

            setInterval(function () {
                $("#jg").fadeOut(1000);
            }, 3000);


        }

        $("#data-table").DataTable({
            "paging": true,
            "lengthChange": true,
            "searching": true,
            "ordering": true,
            "info": true,
            "stateSave": true,
            "autoWidth": true,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "对不起，查询不到任何相关数据",
                "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
                "sInfoEmtpy": "找不到相关数据",
                "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
                "sProcessing": "正在加载中...", "sSearch": "搜索",
                "sUrl": "", //多语言配置文件，可将oLanguage的设置放在一个txt文件中，例：Javascript/datatable/dtCH.txt  
                "oPaginate": {
                    "sFirst": "第一页",
                    "sPrevious": " 上一页 ",
                    "sNext": " 下一页 ",
                    "sLast": " 最后一页 "
                }
            } //多语言配置  
        });
    </script>
@endsection
